import request from "../../utils/request"
Page({

  /**
   * 页面的初始数据
   */
  data: {
    bannerLists:[
      {
        url:'../../static/images/mylove.jpg',
        id:1,
      },
      {
        url:'../../static/images/mylove.jpg',
        id:2,
      },
      {
        url:'../../static/images/mylove.jpg',
        id:3,
      },
    ],
    personalized :[],
    playlists:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getBannerList()
    this.getPersonalized()
    this.getTopList()
  },

  async getBannerList(){
    const result = await request("/banner",{type:1},"GET")
    this.setData({
      bannerLists :result.banners
    })
  },

  async getPersonalized(){
    const result = await request("/personalized",{limit:10},"GET")
    this.setData({
      personalized : result.result
    })
  },

  // 获取排行榜数据
  async getTopList(){
    const list = []
    let index = 0
    while(index<5){
      const result = await request("/top/list",{idx:index++},"GET")
      const playlist = {
        name : result.playlist.name,
        playlist : result.playlist.tracks.slice(0,3)
      }
      list.push(playlist)
    }
    this.setData({
      playlists : list
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})
